package sz.szsmk.citizencard.ui.activity;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.chenenyu.router.annotation.Route;
import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.QuestionActivityBinding;
import sz.szsmk.citizencard.ioc.Compontent.DaggerCommonActivityComponent;
import sz.szsmk.citizencard.model.network.bean.response.QuestionRes;
import sz.szsmk.citizencard.mvp.contract.IQuestionContact;
import sz.szsmk.citizencard.mvp.presenter.QuestionPresenter;
import sz.szsmk.citizencard.ui.adapter.QuestionAdapter;
import sz.szsmk.citizencard.ui.base.IBaseActivity;

import java.util.List;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/7/25 21:35
 * description:
 */
@Route("questions")
public class QuestionActivity extends IBaseActivity<QuestionPresenter, QuestionActivityBinding>
        implements IQuestionContact.IQuestionView {

    private QuestionAdapter questionAdapter;

    @Override
    protected int attachLayoutRes() {
        return R.layout.question_activity;
    }

    @Override
    protected void initInjector() {
        DaggerCommonActivityComponent.builder().appCompontent(DaggerApplication.getAppComponent())
                .build().inject(this);

    }

    @Override
    protected void initViews() {
        dataBinding.titleLayout.settingTitle.setText("常见问题");
        dataBinding.titleLayout.back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        RecyclerView questionRv = dataBinding.questionRv;
        LinearLayoutManager manager = new LinearLayoutManager(this);
        questionRv.setLayoutManager(manager);
        questionAdapter = new QuestionAdapter(this);
        questionRv.setAdapter(questionAdapter);
        mPresenter.getQuestionInfo();
    }

    @Override
    protected void updateViews() {
    }

    @Override
    public void getQuestionInfoSucc(QuestionRes response) {
        List<QuestionRes.InterlcutionListBean> interlcution_list = response.getInterlcution_list();
        if (interlcution_list != null){
            questionAdapter.setItemData(interlcution_list);
            questionAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void getQuestionInfoFail(QuestionRes response) {

    }
}
